<?php

namespace App\Http\Models;


class SpaceShareApply extends BaseMessage
{

    protected $table = 'tspaceshareapply';
    protected $fillable = ['SSACutomerID', 'SSAMessage', 'SSASID'];
    protected $guarded = ['id'];
    public static $rule = array(
        'SSACutomerID' => 'required',
        'SSASID' => 'required',
    );


    public static function doCheck($id)
    {
        if (SpaceShare::where('SSCustomerID', \Illuminate\Support\Facades\Session::get('customer_id'))->where('SSID', $id)->first()) {
            return 1;
        }
        $data = self::where('SSASID', $id)->where('SSACutomerID', \Illuminate\Support\Facades\Session::get('customer_id'))->first();
        if ($data) {
            return 1;
        } else {
            return 0;
        }
    }

    public static function getAoolys($id)
    {
        return self::where('SSASID', $id)->leftJoin('tcustomer', 'tcustomer.CID', '=', 'tspaceshareapply.SSACutomerID')->select('tspaceshareapply.SSAID', 'tspaceshareapply.SSARes', 'tspaceshareapply.SSAMessage', 'tcustomer.CMobile', 'tcustomer.CName')->get();
    }

    public function doChange($SSAID, $SSARes)
    {
        return self::where('SSAID', $SSAID)->update(['SSARes' => $SSARes]);
    }

    public function myApply()
    {
        return self::where('SSACutomerID', \Illuminate\Support\Facades\Session::get('customer_id'))->leftJoin('tspaceshare', 'tspaceshare.SSID', '=', 'tspaceshareapply.SSASID')->select('tspaceshareapply.*', 'tspaceshare.SSTitle', 'tspaceshare.SSBeginAT')->paginate(5);
    }

}
